package com.rykj.energy.common.enums;


public enum HttpErrorCode {

    BUSINESS_ERROR(100000, "业务数据错误"),
    UNKNOW_RESPONSE(404, "接口不存在"),
    TIME_OUT(408, "连接超时"),
    CONNECTION_REFUSED(500, "连接被拒绝"),
    IO_ERROR(501, "连接异常");


    //错误码
    private int code;
    //错误提示信息
    private String message;


    private HttpErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static HttpErrorCode parse(String message) {
        HttpErrorCode status = null;
        for (HttpErrorCode obj : HttpErrorCode.values()) {
            if (obj.getMessage().equals(message)) {
                status = obj;
                break;
            }
        }
        return status;
    }

    public static HttpErrorCode parse(int code) {
        HttpErrorCode status = null;
        for (HttpErrorCode obj : HttpErrorCode.values()) {
            if (obj.getCode() == code) {
                status = obj;
                break;
            }
        }
        return status;
    }

    @Override
    public String toString() {
        return code + "_" + message;
    }
}
